package com.ambulance.project.biz.controller.vr;


import com.ambulance.framework.security.service.SysLoginService;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.domain.AjaxResultData;
import com.ambulance.project.biz.dto.LoginTypeDto;
import com.ambulance.project.biz.dto.pad.PadUserInfo;
import com.ambulance.project.biz.enums.Source;
import com.ambulance.project.biz.service.WebCustomerService;
import com.google.common.collect.Maps;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 人员信息 前端控制器
 * </p>
 *
 * @author zr
 * @since 2020-04-21
 */
@Api(tags = "VR医生-登陆")
@RestController
@RequestMapping(value = "/vr/v1/user", method = RequestMethod.POST)
public class VrUserController {


    @Autowired
    private SysLoginService sysLoginService;

    @Autowired
    private WebCustomerService webCustomerService;

    /**
     * vr眼镜-登陆
     *
     * @param
     * @return
     */
    @ApiOperation(value = "测试登陆", notes = "测试登陆", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "验证嘛", dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    @RequestMapping(value = "/test/login")
    public Object test(
            @RequestBody LoginTypeDto loginTypeDto
    ) {
        System.out.println(loginTypeDto);
        return AjaxResult.success();
    }


    /**
     * vr眼镜-登陆
     *
     * @param code
     * @return
     */
    @ApiOperation(value = "登陆", notes = "登陆", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "验证嘛", dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    @RequestMapping(value = "/login")
    public Object login(@RequestParam(value = "code") String code
    ) {
        String token = sysLoginService.loginNoCaptcha(code, code, Source.MVR);
        Map<String, String> rlt = Maps.newHashMap();
        rlt.put("token", token);
        return AjaxResult.success2("操作成功", rlt);
    }


    @ApiOperation(value = "登陆用户信息", notes = "登陆用户信息", produces = "application/json")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = PadUserInfo.class, message = "响应")
    })
    @RequestMapping(value = "/user/info")
    public Object loginUserInfo(
    ) {

        final PadUserInfo userInfo = webCustomerService.getUserInfo();
        userInfo.setDispatchID(userInfo.getUserMark());
        return AjaxResult.success2("操作成功", userInfo);
    }


}
